package com.mask.common.core.exception;

/**
 * 异常工具类
 */
public class ExceptionUtils {

    /**
     * 抛出业务异常
     */
    public static void throwException(String message) {
        throw new BaseException(message);
    }

    /**
     * 抛出业务异常
     */
    public static void throwException(String code, String message) {
        throw new BaseException(code, message);
    }

    /**
     * 抛出业务异常
     */
    public static void throwException(String code, String message, Object... args) {
        throw new BaseException(code, String.format(message, args));
    }

    /**
     * 抛出参数校验异常
     */
    public static void throwValidException(String message) {
        throw new BaseException("400", message);
    }

    /**
     * 抛出未授权异常
     */
    public static void throwUnauthorizedException(String message) {
        throw new BaseException("401", message);
    }

    /**
     * 抛出禁止访问异常
     */
    public static void throwForbiddenException(String message) {
        throw new BaseException("403", message);
    }

    /**
     * 抛出资源不存在异常
     */
    public static void throwNotFoundException(String message) {
        throw new BaseException("404", message);
    }

    /**
     * 抛出请求方法不支持异常
     */
    public static void throwMethodNotSupportedException(String message) {
        throw new BaseException("405", message);
    }

    /**
     * 抛出参数缺失异常
     */
    public static void throwParamMissingException(String paramName) {
        throw new BaseException("400", "参数缺失：" + paramName);
    }

    /**
     * 抛出参数类型不匹配异常
     */
    public static void throwParamTypeMismatchException(String paramName) {
        throw new BaseException("400", "参数类型不匹配：" + paramName);
    }

    /**
     * 抛出文件上传大小超限异常
     */
    public static void throwFileSizeLimitException() {
        throw new BaseException("400", "文件上传大小超限");
    }

    /**
     * 抛出数据库错误异常
     */
    public static void throwDbException(String message) {
        throw new BaseException("500", "数据库错误：" + message);
    }

    /**
     * 抛出数据完整性违反异常
     */
    public static void throwDataIntegrityViolationException(String message) {
        throw new BaseException("500", "数据完整性违反：" + message);
    }

    /**
     * 抛出数据库连接异常
     */
    public static void throwDbConnectionException(String message) {
        throw new BaseException("500", "数据库连接异常：" + message);
    }
}